package com.sele.context;

import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sele.browers.IBrowerDriver;
import com.sele.dataprovider.IDataProvider;
import com.sele.seleniumGener.ISeleniumGenerator;


public class SeleniumContext {
	private static final Logger logger = LoggerFactory.getLogger(SeleniumContext.class);
	
	private IDataProvider provider;
	private ISeleniumGenerator seleGener;
	private IBrowerDriver browseDriver;
	private WebDriver driver;
	public SeleniumContext(IDataProvider provider,ISeleniumGenerator seleGener,IBrowerDriver browseDriver){
		this.provider = provider;
		this.seleGener = seleGener;
		this.browseDriver = browseDriver;
	}
	
	
	public SeleniumContext(IDataProvider provider,ISeleniumGenerator seleGener,WebDriver driver){
		this.provider = provider;
		this.seleGener = seleGener;
		this.driver = driver;
	}
	
	public void operate(){
		//seleGener.setBrowerDriver(browseDriver);
		if(driver!=null){
			seleGener.setDriver(driver);
		}
		else {
			if(browseDriver!=null){
				seleGener.setBrowerDriver(browseDriver);
			}
			else{
				logger.error("没有设置webdriver");
			}
		}
		
		seleGener.doOperate(provider);
	}

}
